package dao;



import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import po.EmpHistory;
import po.Order;
import po.User;



public class TutorDao extends BaseHibernateDAO{
	private Log log = LogFactory.getLog(TutorDao.class);
	
	//传入订单号 查询该订单 返回Obj对象
	public Object find(int id) {
		log.debug("finding Order instance by id");
		try {
			Object obj = getSession().find(Order.class, id);
			return obj;
		}catch (RuntimeException re) {
			log.error("find by id failed", re);
			throw re;
		}
	}
	//传入用户id 搜索用户信息
	public Object findInfo(int id) {
		log.debug("finding User instance by id");
		try {
			Object obj = getSession().find(User.class, id);
			return obj;
		}catch (RuntimeException re) {
			log.error("find by id failed", re);
			throw re;
		}
	}
	
	//更新订单
	public void updateStatus(Order ord) {
		log.debug("updating order");
		try {
			System.out.println("新地址："+ord.getAddress()+" "+ord.getOrderID());
			getSession().update(ord);
			System.out.println("更新成功！");
			log.debug("update successful");
		} catch (RuntimeException re) {
			log.error("update failed", re);
			throw re;
		}
	}
	//发布课程
	public void issue(Order ord) {
		log.debug("issue order");
		try {
			getSession().save(ord);
			System.out.println("家教发布课程成功！");
			log.debug("issue successful");
		} catch (RuntimeException re) {
			log.error("issue failed", re);
			throw re;
		}
	}
	//订单结束后，转移到历史表中
	public void saveHistory(EmpHistory his) {
		try {
			getSession().save(his);		
		} catch (RuntimeException re) {		
			throw re;
		}
	}
	//删除课程
	public void delete(Order ord) {
		log.debug("delete course");
		try {
			getSession().delete(ord);		
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}
	
	
}
